package com.itheima.utils;

import com.itheima.pojo.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;
import java.security.Key;
import java.util.Date;
import java.util.Map;

@Component
public class JwtUtils {


    private static String key="9ajdijadawjkdbhabhjjygdSVRIRUlNQQ=aaadaddaddada24raadad=";
    //private static final Key SECRET_KEY = Keys.secretKeyFor(SignatureAlgorithm.HS256);

    private static long time=43200000L;
    public static String generateJwt(Map<String,Object> claims) {
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, key)
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+time))
                .compact();
    }

    public static Claims parseJwt(String token) {
        return Jwts.parser()
                .setSigningKey(key)
                .parseClaimsJws(token)
                .getBody();
    }
    public static boolean verfiy(String token){
        try {
            parseJwt(token);
            return true;
        } catch (Exception e) {
        }
        return false;
    }
}
